package com.tianshuo;

import com.amos.log.configure.EnableLogAspect;
import com.tianshuo.model.Child;
import com.tianshuo.model.Father;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

/**
 * @ClassName : TianshuoSpringbootApplication
 * @Description : springboot启动应用
 * @Author : tianshuo
 * @Date: 2020-10-31 10:48
 */
// 用于手动开启的log拦截
@EnableLogAspect
@SpringBootApplication
public class TianshuoSpringbootApplication {
	public static void main(String[] args) {
		SpringApplication.run(TianshuoSpringbootApplication.class);
	}

	// 当beanName为father的bean，不存在时，执行@Bean的方法
	@Bean
	@ConditionalOnMissingBean (name="father")
	public Father father() {
		System.out.println("new father对象");
		return new Father();
	}
    // 当beanName为father的bean存在是执行@Bean的方法
	@Bean
	@ConditionalOnBean(name="father")
	public Child child() {
		System.out.println("child对象 ");
		return new Child();
	}
}

